<template>
  <el-dialog
    title="编辑"
    :visible.sync="editVisible"
    width="30%"
    :before-close="close"
  >
    <el-form ref="form" :model="form">
      <el-form-item label="姓名" label-width="80px">
        <el-input v-model="form.userName" autocomplete="off" />
      </el-form-item>
      <el-form-item label="账号" label-width="80px">
        <el-input v-model="form.account" autocomplete="off" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleEditClose">取消</el-button>
      <el-button type="primary" @click="handleEditSubmit">保存</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'Add',
  props: {
    editVisible: {
      type: Boolean,
      default: false
    },
    listItemInfo: {
      type: Object,
      default() {
        return {
          userName: '',
          account: ''
        }
      }
    }
  },
  data() {
    return {
      form: {
        userName: '',
        account: ''
      }
    }
  },
  watch: {
    listItemInfo(val) {
      this.form = val
    },
    deep: true
  },
  methods: {
    handleEditClose() {
      this.$emit('handleEditClose', false)
      this.$refs.form.resetFields()
      this.$data.form = JSON.parse(JSON.stringify(this.$options.data().form))
    },
    handleEditSubmit() {
      this.$emit('handleEditSubmit', this.form)
      this.$refs.form.resetFields()
      this.$data.form = JSON.parse(JSON.stringify(this.$options.data().form))
    },
    close() {
      this.$emit('handleEditClose', false)
      this.$refs.form.resetFields()
      this.$data.form = JSON.parse(JSON.stringify(this.$options.data().form))
    }
  }
}
</script>

<style scoped>

</style>
